<?php
global $_RQ,$_AR;
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$return=array();
if($_RQ['op']=='list'){
	$pindex = max(1, intval($_SESSION['page']));
	$psize = 10;
	$params=array('uniacid'=>$_SESSION['uniacid']);
    if(!empty($_RQ['name'])){
		$params['name like']='%'.trim($_RQ['name']).'%';
		$return['params']['name']=$_RQ['name'];
	}
	if(!empty($_RQ['mobile'])){
		$params['mobile']=trim($_RQ['mobile']);
		$return['params']['mobile']=$_RQ['mobile'];
	}
	$fields=array('id','name','mobile','stop','createtime');
    $orderby='createtime desc';
	$total='';
	$return['list']=pdo_getslice('jy_taxi_member',$params,array($pindex,$psize),$total,$fields,'',$orderby);
	foreach($return['list'] as &$v){
		$v['createtime']=date('Y-m-d H:m:s',$v['createtime']);
		}
	$htmls=array(
		'type'=>'list',
		'tabs'=>array(
			array('op'=>'list','title'=>'用户管理'),
			array('op'=>'edit','title'=>'添加用户'),
		),
		'list'=>array('data'=>'list','list'=>array(
			array('name'=>'id','title'=>'id','type'=>'string'),
			array('name'=>'name','title'=>'姓名','type'=>'string'),
			array('name'=>'mobile','title'=>'手机号','type'=>'string'),
			array('name'=>'stop','title'=>'是否黑名单','type'=>'radio','options'=>'stop'),
			array('name'=>'createtime','title'=>'创建时间','type'=>'string'),			
		)),
		'search'=>array(
			array('name'=>'name','title'=>'姓名','type'=>'string'),
			array('name'=>'mobile','title'=>'手机号','type'=>'string'),
			
		)
	);
	$return['htmls']=$htmls;
	$return['stop']=array('1'=>'是','0'=>'否');
	exi($return);
	}
	if($_RQ['op']=='edit'){
	$id=intval($_RQ['id']);
	if($id){
	$item=pdo_get('jy_taxi_member',array('id'=>$id));
	}else{
		$item=array();
	}
    $return['item']=$item;
	$return['stop']=array('1'=>'是','0'=>'否');
	$htmls=array(
		'type'=>'edit',
		'post'=>'post',
		'desc'=>'会员设置',
		'tabs'=>array(
			array('op'=>'list','title'=>'会员管理'),
			array('op'=>'edit','title'=>'添加会员')
		),
		'edit'=>array(
			
			array('name'=>'name','title'=>'姓名','type'=>'string'),
			array('name'=>'mobile','title'=>'手机号','type'=>'string'),
			array('name'=>'stop','title'=>'是否黑名单','type'=>'radio','options'=>'stop'),
				
			)
			);
	$return['htmls']=$htmls;
	exi($return);
	}
	if($_RQ['op']=='post'){
	$postdata=get_postdata();
	$data=array_fields(array('name','mobile','stop'),$postdata);
	if(!$data['name']){
		exi('请填写姓名','');
	}
	if(!intval($data['mobile']) || strlen($data['mobile'])!=11){
		exi('请填写正确手机号','');
	}
	$id=intval($postdata['id']);
			if($id){
				pdo_update('jy_taxi_member',$data,array('id'=>$id));
				exi('设置成功！','','list');
			}else{
			    $data['uniacid']=$_SESSION['uniacid'];
				$data['createtime']=TIMESTAMP;
				pdo_insert('jy_taxi_member',$data);
				exi('添加成功！','','list');
			}
			}
			if($_RQ['op']=='del'){

	$id=intval($_RQ['id']);
	if($id){
		pdo_delete('jy_taxi_member',array('id'=>$id));	
	}
	$del=trim($_RQ['del'],';');
	if($del){
		$del=explode(';',$del);
		foreach($del as $id){
			$id=intval($id);
			if($id){
				pdo_delete('jy_taxi_member',array('id'=>$id));
			}
		}
	}
	exi('删除成功！');
}
?>